/*! \file
 * \brief Interface file for the file-input.
 * \author Ivo Wingelaar
 * \date 2011
 * \version 0.1.0
 * \copyright GNU Lesser General Public License v3
 */

#ifndef __MYTH_FILE_INPUT_FILE_C_HPP_INCLUDED__
#define __MYTH_FILE_INPUT_FILE_C_HPP_INCLUDED__

#include <stdio.h>
#include "MythFile.hpp"

namespace Myth
{
namespace File
{

//! A reference counted input interface to a file in the filesytem.
class InputFile_C : public Stream::Input
{
public:
    //! Creates an input from a file.
    /*!
     * \param[in] stream_name Name of the stream.
     * \param[in] file_name Path to the file you want to open for reading.
     */
    InputFile_C(const std::string& stream_name, const std::string& file_name);

    //! Virtual destructor.
    virtual ~InputFile_C(void);

    //! Reads an amount of bytes from the input.
    /*!
     * \return The number of bytes actually read.
     * \param[out] buffer The place to store the data.
     * \param[in] size The number of bytes to request.
     * \throw InputException if something went wrong.
     */
    virtual uintptr_t read(void* buffer, uintptr_t size);

    //! Changes the position in the data-input.
    /*!
     * \return If the specifief position was reached true is returned, false otherwise.
     * \param[in] position The position you want to seek to.
     * \param[in] relative Should we change the position relative to this, or absolute?
     */
    virtual bool seek(uintptr_t position, bool relative = false);

    //! Returns the size of the input.
    /*!
     * \return The size of the input.
     */
    virtual uintptr_t get_size(void) const;

    //! Returns the current position of the input.
    /*!
     * \return The current position of the input.
     */
    virtual uintptr_t get_pos(void) const;

    //! Return if the file was opened succesfuly
    /*!
     * \return True if the file was opened, false otherwise.
     */
    bool is_open(void) const;

private:
    //! Tries to open the file.
    void open_file(void);

    //! A pointer to the FILE.
    FILE *mFile;
    //! Size of the file.
    uintptr_t mFileSize;
    //! Name of the file.
    std::string mFileName;
};

} // namespace File
} // namespace Myth

#endif // __MYTH_FILE_INPUT_FILE_C_HPP_INCLUDED__
